package com.zis.system.web;

import com.alibaba.fastjson.JSONObject;
import com.zis.starter.core.ResponseEntity;
import com.zis.starter.core.SearchParams;
import com.zis.system.client.GroupClient;
import com.zis.system.inter.IGroupInter;
import com.zis.system.inter.IGroupResInter;
import com.zis.system.model.Group;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Create by wangshen 2018/4/9
 */
@RestController
@RequestMapping("/api/system/group")
public class GroupController {

    @Autowired
    private GroupClient groupClient;

    /**
     * 分页查询
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public PageQuery<Group> findByPage(@RequestBody SearchParams params) throws Exception {
        return groupClient.findByPage(params);
    }


    /**
     * 新增
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResponseEntity insert(@RequestBody Group model) throws Exception {
        return groupClient.insert(model);
    }

    /**
     * 修改
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseEntity update(@RequestBody Group model) throws Exception {
        return groupClient.update(model);
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public ResponseEntity delete(@PathVariable("id") String id) throws Exception {
        return groupClient.delete(id);
    }

    /**
     * 查询全部转为json
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/all/json", method = RequestMethod.GET)
    public ResponseEntity findAllToJSON() throws Exception {
        return groupClient.findAllToJSON();
    }

    /**
     * 角色资源保存
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/res/save", method = RequestMethod.POST)
    public ResponseEntity groupResSave(@RequestBody JSONObject params) throws Exception {
        return groupClient.groupResSave(params);
    }

    /**
     * 获取角色资源
     * @param groupId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/res/tree/{groupId}", method = RequestMethod.GET)
    public ResponseEntity findGroupResTree(@PathVariable("groupId") String groupId) throws Exception {
        return groupClient.findGroupResTree(groupId);
    }
}
